class Solution {
    /**
     * O(m+nlogn)，只关心石头并不关心有多少石头，使用哈希就够了
     */
    public List<Integer> relocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int j : nums) {
            var pre = map.getOrDefault(j, 0);
            map.put(j, pre+1);
        }
        for (int i = 0; i < moveFrom.length; i++) {
            var c = map.remove(moveFrom[i]);
            var pre = map.getOrDefault(moveTo[i], 0);
            map.put(moveTo[i], pre + c);
        }
        return map.keySet().stream().sorted().toList();
    }
}